using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Tools;
using Pixysoft.Framework.Verifications;
using Pixysoft.Framework.Noebe;
using Pixysoft.Weblications.Sango.Entities;
using Pixysoft.Weblications.Sango.Formular;

namespace Pixysoft.Weblications.Sango.Environment
{
    class SysFameSettingHelper
    {
        private static List<Sys_Famesetting> orms = new List<Sys_Famesetting>();

        public static void initialize()
        {
            orms = SettingHelper.GetNoebe().EntityNoebeCommand.Select<Sys_Famesetting>();

            LoggerHelper.Info("initialize Sys_Famesetting.countin {0}", orms.Count);
        }

        public static Sys_Famesetting getDefaultFame()
        {
            return getFrame(PlayerFormular.default_fame_serialcode);
        }

        public static Sys_Famesetting getFrame(long typecode)
        {
            Sys_Famesetting orm = tryGetFrame(typecode);

            if (orm == null)
                throw Exceptions.VerificationFailedException(typecode);

            return orm;
        }

        public static Sys_Famesetting tryGetFrame(long typecode)
        {
            foreach (Sys_Famesetting orm in orms)
            {
                if (orm.Fametitletypecode == typecode)
                    return orm;
            }

            return null;
        }

        public static List<Sys_Famesetting> searchAll()
        {
            return orms;
        }
    }
}